package cn.thr.pethome.user.service.impl;

import cn.thr.pethome.base.service.Impl.BaseServiceImpl;
import cn.thr.pethome.user.domain.Employee;
import cn.thr.pethome.user.mapper.EmployeeMapper;
import cn.thr.pethome.user.query.EmployeeQuery;
import cn.thr.pethome.user.service.IEmployeeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;



    @Override
    public List<Employee> findAll() {
        List<Employee> lists = employeeMapper.findAll();
        List<Employee> employeeList = new ArrayList<>();
        for (Employee list : lists) {
            Employee employee = new Employee();
            BeanUtils.copyProperties(list,employee);
            employeeList.add(employee);
        }
        return employeeList;
    }

    @Transactional
    @Override
    public void delete(Long id) {
        Employee one = employeeMapper.findOne(id);
        if(one.getState() == 0){
            employeeMapper.delete(id);
        }else {
            throw  new RuntimeException("现在是开起的不能删除");
        }

    }

    @Override
    public Employee findByLogininfoId(Long id) {
        return employeeMapper.findByLogininfoId(id);
    }

    @Override
    public List<Long> findRoleByEmpId(Long id) {
        return employeeMapper.findRoleByEmpId(id);
    }
}
